home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / RAYTRACE.ZIP / HTASM.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-09-27  |  5.5 KB  |  184 lines

  1. ; Assembler portion of Height Mapping test
  2. ; Started: 06/05/96
  3. ; Module: HTASM.ASM
  4.  
  5.     IDEAL
  6.     JUMPS
  7.     P386
  8.     P387
  9.  
  10.  
  11.     MASM
  12.     .MODEL FLAT
  13.     .CODE
  14.     IDEAL
  15.  
  16.     extrn   _OffsetTable:word
  17.     extrn   _Buffer:dword
  18.     extrn   _Color:dword
  19.     extrn   _World:dword
  20.     extrn   _USERX:word
  21.     extrn   _USERY:word
  22.     extrn   _xPosns:word
  23.     extrn   _yPosns:word
  24.     extrn   _startpostable:word
  25.     extrn   _RangeTable:dword
  26.     extrn   _UserAlt:word
  27.     extrn   _Used:byte
  28.     extrn   _CurrentColumn:dword
  29.     extrn   _CurrentAngle:dword
  30.     extrn   _HighRow:dword
  31.     extrn   _OldPos:dword
  32.     extrn   _CurrentColor:byte
  33.  
  34.  
  35.     public  CopyVertical_
  36.     public  FillLinearBuffer_
  37.     public  FillUsedBuffer_
  38.  
  39. ;==============================================================================
  40. ; Copy a linear buffer to a vertical column of a video buffer
  41. ;==============================================================================
  42. proc    CopyVertical_ near
  43.     mov     eax,[_HighRow]  ; Pick up the starting row to draw
  44.     cmp     eax,200         ; If at the bottom of the screen
  45.     jae     noCopy          ; then get out now
  46.  
  47.     push    ebx
  48.     push    ecx
  49.  
  50.     push    esi
  51.     push    edi
  52.  
  53.     mov     edi,[_Buffer]               ; Buffer to draw into
  54.     movzx   ebx,[_OffsetTable+eax*2]    ; Pre-calculated video offset
  55.     add     edi,ebx
  56.     add     edi,[_CurrentColumn]        ; Display column to start with
  57.  
  58.     mov     esi,offset _Used            ; Buffer to get data from
  59.     add     esi,eax                     ; Plus the start row
  60.  
  61.     mov     ecx,200                     ; Total rows that can be drawn
  62.     sub     ecx,eax                     ; Minus our starting row
  63.     mov     ebx,320                     ; Amount to skip for each row
  64.  
  65. cvLoop:
  66.     mov     al,[esi]                    ; Current pixel
  67.     mov     ah,al                       ; Setup to copy to columns at once
  68.     mov     [edi],ax
  69.     inc     esi                         ; Next row of source buffer
  70.     add     edi,ebx                     ; Next row of video buffer
  71.     dec     ecx
  72.     jnz     cvLoop
  73.  
  74.     pop     edi
  75.     pop     esi
  76.  
  77.     pop     ecx
  78.     pop     ebx
  79.  
  80. noCopy:
  81.     ret
  82.     endp
  83.  
  84.  
  85. ;==============================================================================
  86. ; void FillLinearBuffer(short startpos,short i);
  87. ;==============================================================================
  88. proc    FillLinearBuffer_
  89.  
  90.     cmp     eax,[_OldPos]       ; Are we beyond the last remembered row?
  91.     jle     noFill              ; Nope, get out now
  92.     cmp     eax,0               ; Are we in bounds for the screen?
  93.     jle     noFill              ; Nope
  94.     cmp     eax,200             ; Check if beyond last row
  95.     jge     noFill              ; Get out if so
  96.  
  97.     push    ebx
  98.     push    ecx
  99.     push    edx
  100.     push    edi
  101.  
  102.     mov     ebx,[_OldPos]
  103.     cmp     ebx,200             ; Is last remembered row out of bounds?
  104.     jge     nfDone              ; Yes, getout
  105.  
  106.     cmp     dx,10               ; Is length near the bottom of the screen?
  107.     jge     short nfLarger      ; Not yet
  108.  
  109.     mov     ecx,200
  110.     sub     ecx,ebx             ; Get 200 - OldPos for number of rows
  111.     mov     eax,199             ; and set our starting row at bottom of screen
  112.     jmp     short nfDoFill      ; then continue with the fill
  113.  
  114.  
  115. nfLarger:
  116.     mov     ecx,eax             ; Get our starting row
  117.     sub     ecx,ebx             ; Minus last remembered row
  118.  
  119. nfDoFill:
  120.     sub     eax,ecx             ; Subtract number of rows from starting row
  121.     jnc     short nfNotNegative ; Didn't go above top
  122.  
  123.     add     ecx,eax             ; Else adjust the number of rows
  124.     xor     eax,eax             ; And set our starting row at top
  125.  
  126. nfNotNegative:
  127.     cmp     eax,[_HighRow]      ; Keep our highest row used updated
  128.     jge     short nfNotLess     ; Nope, not less than highest
  129.     mov     [_HighRow],eax      ; Else save current high row
  130.  
  131. nfNotLess:
  132.     mov     edi,offset _Used    ; Get our linear buffer
  133.     add     edi,eax             ; Add in the row we are going to start with
  134.  
  135.     mov     al,[_CurrentColor]  ; Get the color we want to use
  136.     mov     ah,al
  137.     mov     bx,ax               ; Hold onto it for a second
  138.     shl     eax,16              ; Move to the upper end
  139.     mov     ax,bx               ; Now eax contains 32 bit of color
  140.  
  141.     mov     ebx,ecx
  142.     shr     ecx,2               ; Divide length by four
  143.     rep     stosd               ; and blast in (sort of) 4 bytes at a time
  144.     and     ebx,3               ; get the remaining bytes to copy
  145.     mov     ecx,ebx
  146.     rep     stosb               ; and store them as bytes
  147.  
  148. nfDone:
  149.     pop     edi
  150.     pop     edx
  151.     pop     ecx
  152.     pop     ebx
  153.  
  154.  
  155. noFill:
  156.     ret
  157.     endp
  158.  
  159. ;==============================================================================
  160. ;
  161. ;==============================================================================
  162. proc FillUsedBuffer_ near
  163.     push    ecx
  164.     push    edi
  165.     mov     al,[_CurrentColor]
  166.     mov     ah,al               ; Put color into AX
  167.     mov     cx,ax               ; Hold onto it for a second
  168.     shl     eax,16              ; Move color to upper 16 bits
  169.     mov     ax,cx               ; And then fill lower 16 bits again
  170.     mov     edi,offset _Used
  171.     add     edi,100             ; Start 100 bytes into buffer
  172.  
  173.     mov     ecx,25              ; Fill 25 * 4 = 100 bytes of the buffer
  174.     rep     stosd
  175.  
  176.     pop     edi
  177.     pop     ecx
  178.     ret
  179.     endp
  180.  
  181.  
  182.     end
  183.  
  184.